package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.Requisitions;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Appliance;
import com.ruoyi.system.service.IApplianceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 器具租赁Controller
 * 
 * @author ruoyi
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/system/appliance")
public class ApplianceController extends BaseController
{
    @Autowired
    private IApplianceService applianceService;

    /**
     * 查询器具租赁列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Appliance appliance)
    {
        startPage();
        List<Appliance> list = applianceService.selectApplianceList(appliance);
        return getDataTable(list);
    }

    /**
     * 查询器具租赁
     */
    @GetMapping("/queryApplianceList")
    public TableDataInfo queryApplianceList(Requisitions requisitions)
    {
        startPage();
        List<Requisitions> list = applianceService.queryApplianceList(requisitions);
        return getDataTable(list);
    }

    /**
     * 导出器具租赁列表
     */
    @Log(title = "器具租赁", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Appliance appliance)
    {
        List<Appliance> list = applianceService.selectApplianceList(appliance);
        ExcelUtil<Appliance> util = new ExcelUtil<Appliance>(Appliance.class);
        return util.exportExcel(list, "器具租赁数据");
    }

    /**
     * 获取器具租赁详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(applianceService.queryApplianceListById(id));
    }
    /**
     * 生成租赁采购
     */
    @Log(title = "生成租赁采购", businessType = BusinessType.INSERT)
    @PostMapping("/addPurchase")
    public AjaxResult addPurchase(@RequestBody Requisitions requisitions)
    {
        return toAjax(applianceService.insertPurchase(requisitions));
    }

    /**
     * 新增器具租赁
     */
    @Log(title = "器具租赁", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Requisitions requisitions)
    {
        return toAjax(applianceService.insertAppliance(requisitions));
    }

    /**
     * 修改器具租赁
     */
    @Log(title = "器具租赁", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Requisitions requisitions)
    {
        return toAjax(applianceService.updateAppliance(requisitions));
    }

    /**
     * 删除器具租赁
     */
    @Log(title = "器具租赁", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(applianceService.deleteRequisitionsById(id));
    }
}
